<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('移库历史任务管理')"/>
    <style>
        [v-cloak] {
            display: none;
        }
        .el-date-editor.el-input, .el-date-editor.el-input__inner {
            width: 200px!important;
        }
        .el-input__icon {
            line-height: 0!important;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li v-if="checkedSearch.indexOf('任务编号') != -1">
                            任务编号：<input type="text" name="taskNumber"/>
                        </li>
                        <li v-if="checkedSearch.indexOf('托盘号') != -1">
                            托盘号：<input type="text" name="boxCode"/>
                        </li>
                        <li v-if="checkedSearch.indexOf('状态') != -1">
                            状态：
                            <select name="state">
                                <option value="">全部</option>
                                <option value="0">已下发</option>
                                <option value="1">执行中</option>
                                <option value="2">报错</option>
                                <option value="3">已完成</option>
                                <option value="4">取货货物不存在</option>
                                <option value="5">作废</option>
                                <option value="6">强制完成</option>
                                <option value="7">需盘点</option>
                                <option value="8">在途</option>
                            </select>
                        </li>
                        <li v-show="checkedSearch.indexOf('任务开始时间') != -1">
                            <label>任务开始时间：</label>
                            <el-date-picker
                                name="startTime"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                v-model="startTimeValue"
                                type="datetime"
                                @change="compare"
                                placeholder="开始时间">
                            </el-date-picker>
                            <span>-</span>
                            <el-date-picker
                                name="endTime"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                v-model="endTimeValue"
                                type="datetime"
                                @change="compare"
                                placeholder="结束时间">
                            </el-date-picker>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" :class="flag ? 'disabled' : ''" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            <a class="btn btn-success btn-rounded btn-sm" @click="moreSearch()"><i class="fa fa-edit"></i>&nbsp;更多</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <el-dialog title="搜索条件" width="200px" :visible.sync="showMore">
            <el-row>
                <el-col :span="24">
                    <el-checkbox style="margin-left: 28px" :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
                    <el-checkbox-group v-model="checkedSearch" @change="handleCheckedSearchChange">
                        <el-checkbox style="display: block;margin-left: 28px" v-for="item in searches" :label="item" :key="item" v-cloak>{{item}}</el-checkbox>
                    </el-checkbox-group>
                </el-col>
            </el-row>
        </el-dialog>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var prefix = ctx + "in/billlIntaskInfo";

    const searchOptions = ['任务编号', '托盘号', '状态', '任务开始时间'];

    var app = new Vue({
        el: '.container-div',
        data: {
            showMore: false,
            checkAll: false,
            checkedSearch: ['托盘号', '状态', '任务开始时间'],
            searches: searchOptions,
            isIndeterminate: true,
            startTimeValue: '',
            endTimeValue: '',
            flag: false
        },
        methods: {
            compare: function(){
                if(this.startTimeValue != '' && this.endTimeValue != ''){
                    if(this.startTimeValue != null && this.endTimeValue != null){
                        var a = new Date(this.startTimeValue);
                        var b = new Date(this.endTimeValue);
                        if(a > b){
                            $.modal.alertWarning("结束时间需大于开始时间");
                            this.flag = true;
                        }else{
                            this.flag = false;
                        }
                    }else if(this.startTimeValue == null){
                        this.startTimeValue = '';
                        this.flag = false;
                    }else if(this.endTimeValue == null){
                        this.endTimeValue = '';
                        this.flag = false;
                    }
                }
            },
            moreSearch(){
                this.showMore = true;
            },
            handleCheckAllChange(val){
                this.checkedSearch = val ? searchOptions : [];
                this.isIndeterminate = false;
            },
            handleCheckedSearchChange(value){
                let checkedCount = value.length;
                this.checkAll = checkedCount === this.searches.length;
                this.isIndeterminate = checkedCount > 0 && checkedCount < this.searches.length;
            },
            today(){
                var date = new Date();
                var Y = date.getFullYear() + '-';
                var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
                return Y + M + D;
            }
        },
        created(){
            this.startTimeValue = this.today() + " 00:00:00";
        }
    })

    $(function() {
        var options = {
            url: "/remove/taskInfo/moveTaskHistoryList",
            modalName: "移库历史任务管理",
            queryParams: queryParams,
            columns: [
                {
                    field: 'id',
                    title: 'ID',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'taskNumber',
                    title: '任务编号',
                    align: 'center'
                },
                {
                    field: 'boxCode',
                    title: '托盘号',
                    align: 'center',
                },
                {
                    field: 'memo',
                    title: '源货位',
                    align: 'center',
                },
                {
                    field: 'moveTaskAimCell',
                    title: '目标货位',
                    align: 'center',
                },
                {
                    field: 'state',
                    title: '状态',
                    align: 'center',
                    formatter: function(value, row, index){
                        var actions = [];
                        if(value == 0){
                            actions.push("<span style='display: inline-block;padding: 0 5px;line-height: 22px;color: #FFFFFF;background-color: #1ab394;border-radius: 3px'>已下发</span>");
                        }else if(value == 1){
                            actions.push("<span style='display: inline-block;padding: 0 5px;line-height: 22px;color: #FFFFFF;background-color: #1ab394;border-radius: 3px'>执行中</span>");
                        }else if(value == 2){
                            actions.push("<span style='display: inline-block;padding: 0 5px;line-height: 22px;color: #FFFFFF;background-color: #1ab394;border-radius: 3px'>报错</span>");
                        }else if(value == 3){
                            actions.push("<span style='display: inline-block;padding: 0 5px;line-height: 22px;color: #FFFFFF;background-color: #1ab394;border-radius: 3px'>已完成</span>");
                        }else if(value == 4){
                            actions.push("<span style='display: inline-block;padding: 0 5px;line-height: 22px;color: #FFFFFF;background-color: #1ab394;border-radius: 3px'>取货货物不存在</span>");
                        }else if(value == 5){
                            actions.push("<span style='display: inline-block;padding: 0 5px;line-height: 22px;color: #FFFFFF;background-color: #ed5565;border-radius: 3px'>作废</span>");
                        }else if(value == 6){
                            actions.push("<span style='display: inline-block;padding: 0 5px;line-height: 22px;color: #FFFFFF;background-color: #f8ac59;border-radius: 3px'>强制完成</span>");
                        }else if(value == 7){
                            actions.push("<span style='display: inline-block;padding: 0 5px;line-height: 22px;color: #FFFFFF;background-color: #f8ac59;border-radius: 3px'>需盘点</span>");
                        }else if(value == 8){
                            actions.push("<span style='display: inline-block;padding: 0 5px;line-height: 22px;color: #FFFFFF;background-color: #f8ac59;border-radius: 3px'>在途</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'taskStartTime',
                    title: '任务开始时间',
                    align: 'center',
                    formatter: function(value, row, index){
                        return value.slice(0, 19)
                    }
                },
                {
                    field: 'taskEndTime',
                    title: '任务结束时间',
                    align: 'center',
                    formatter: function(value, row, index){
                        if(value == null){
                            return '-'
                        }else{
                            return value.slice(0, 19)
                        }
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function queryParams(params){
        return {
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            orderByColumn: params.sort,
            isAsc: params.order,
            startTime: app.startTimeValue
        };
    }
</script>
</body>
</html>
